#!/usr/local/bin/python
# -*- coding: utf-8 -*-

'''
公寓、房间模块
'''
import logging, traceback
from tornado.escape import json_encode, json_decode


import log
import util
import const
import time
import datetime
import user
from home import home
from mysqlHelper import mysql

from hall_of_fame import HallOfFameManager
from bar_order import BarOrderManager
    
logger = logging.getLogger(__name__)


#进入房间
def method_enter_house(request, data): 
    cmd = 'enter_house'
    data = json_decode(data)
    tmpSendMsgUtil = util.SendMsgUtil(request)
    #设置当前位置为house
    if not user.UserManager.set_user_palce(request, "house"):
        tmpSendMsgUtil.update_res("user_is_null")    
    
    tmpUser = user.UserManager.get_user_by_request(request)
    if not tmpUser:
    	return
    tmpUid = tmpUser.getUID()
    roomer_uid = data['owner']
    #进入房间相关操作
    res = home.enter_house(request, data,)
    #返回结果到客户端
    if res == False:
        return
    if res["res"] != True:
        tmpSendMsgUtil.update_res(res["res"])
    else:
        tmpSendMsgUtil.add_item("clean", res['clean'])
        tmpSendMsgUtil.add_item("assets", res['assets'])
        tmpSendMsgUtil.add_item("roomer_uid", res['roomer_uid'])
        tmpSendMsgUtil.add_item("max_clean",const.Config_clean_max())
        tmpSendMsgUtil.add_item("left_roomer_gold",res['left_roomer_gold']) 
        tmpSendMsgUtil.add_item("total_roomer_gold",res['total_roomer_gold'])
        tmpSendMsgUtil.add_item("gold_level",res['gold_level'])
        tmpSendMsgUtil.add_item("gold_status",res['gold_status'])
        tmpSendMsgUtil.add_item("gold_rest",res['gold_rest'])
        tmpSendMsgUtil.add_item("age", res['age'])
        tmpSendMsgUtil.add_item("province", res['province'])
        tmpSendMsgUtil.add_item("city", res['city'])
        tmpSendMsgUtil.add_item("nickname", res['nickname'])
        tmpSendMsgUtil.add_item("height", res['height'])
        tmpSendMsgUtil.add_item("sex", res['sex'])
        tmpSendMsgUtil.add_item("my_bodyinfo", res['my_bodyinfo'])   
        tmpSendMsgUtil.add_item("is_steal", res.get("is_steal"))    #是否偷过钱 "yes/no"
        tmpSendMsgUtil.add_item("level", res['level'])
        tmpSendMsgUtil.add_item("charm", res['charm'])
       
        #tmpGameinfo = user.UserManager.get_user_game_info(roomer_uid, 'my_furniture')
        #获取用户墙纸ID
        my_furniture = {}
        wallpaper_goods_id = 0
        tmpRoomer = user.UserManager.get_user_by_uid(roomer_uid);
        if tmpRoomer:
            tmpGameinfo = tmpRoomer.m_userinfo
            if tmpGameinfo:
                my_furniture = tmpGameinfo.get('my_furniture')
        else:
            tmpGameinfo = user.UserManager.get_user_wear_info(roomer_uid,'my_furniture')
            if tmpGameinfo:
                my_furniture = tmpGameinfo.get('my_furniture')
                if my_furniture:
                    my_furniture = json_decode(my_furniture);    
                            
        if my_furniture:
            print type(my_furniture)
            wallpaper = my_furniture.get('wallpaper')
            if wallpaper:
                for k,v in wallpaper.iteritems():                           
                    info = v.get('info')
                    if info:
                        wallpaper_goods_id = info[0]['id']
                        break
                
        tmpSendMsgUtil.add_item("wallpaper_goods_id",wallpaper_goods_id) 
        if tmpUid != roomer_uid:#增加统计数量
            user.UserManager.updateUserCount('count_visited', 1, roomer_uid)
            
            #----通知php, 写信息到用户被关注的人员的文本
            user.UserManager.sendLogFriendInfoUrl(tmpUid, tmpUser.getNickname(), cmd, roomer_uid)
        
    tmpSendMsgUtil.send(cmd)


#进入公寓
def method_enter_room(request, data): 
    cmd = 'enter_room'
    tmpSendMsgUtil = util.SendMsgUtil(request)
    if not user.UserManager.set_user_palce(request, "room"):
        tmpSendMsgUtil.update_res("user_is_null")
    tmpSendMsgUtil.send(cmd)


#衣服穿戴
def method_set_clothing(request, data): 
    cmd = 'set_clothing'
    data = json_decode(data)   
    res = home.save_my_bodyinfo(request, data)   
    tmpSendMsgUtil = util.SendMsgUtil(request) 
    if res["res"] != True:
        tmpSendMsgUtil.update_res(res["res"])
    else:     
        tmpSendMsgUtil.add_item("user", res['user'])  
        tmpSendMsgUtil.add_item("goods", res['goods'])
        tmpSendMsgUtil.add_item("exp_goods", res['exp_goods'])
    tmpSendMsgUtil.send(cmd)

    
#家具摆放
def method_set_furniture(request, data): 
    cmd = 'set_furniture'
    data = json_decode(data)
    tmpSendMsgUtil = util.SendMsgUtil(request)    
    
    
    res = home.set_furniture(request, data)
    if res["res"] != True:
        tmpSendMsgUtil.update_res(res["res"])
        
    tmpSendMsgUtil.send(cmd)
    
    
#打扫房间
def method_clean_house(request, data): 
    cmd = 'clean_house'
    data = json_decode(data)
    tmpSendMsgUtil = util.SendMsgUtil(request)
    res = home.clean_house(request, data)
    if res == False:
        return
    if res["res"] != True:
        tmpSendMsgUtil.update_res(res["res"])
        if res["res"] == 'already_clean':
            tmpSendMsgUtil.add_item("clean", res["clean"])    
    else:
        tmpSendMsgUtil.add_item("add_clean", res["add_clean"])
        tmpSendMsgUtil.add_item("clean", res["clean"])  
        user.UserManager.updateUserCount('count_cleaned', 1, data.get('uid'))   #增加统计数量       
    tmpSendMsgUtil.send(cmd)
    

#偷钱
def method_steal_gold(request, data): 
    cmd = 'steal_gold'
    data = json_decode(data)
    tmpSendMsgUtil = util.SendMsgUtil(request)
    res = home.steal_gold(request, data)
    if res["res"] != True:
        tmpSendMsgUtil.update_res(res["res"])
    tmpSendMsgUtil.send(cmd)
    
#存钱
def method_save_gold(request,data):
    '''存钱'''
    cmd = 'save_gold'
    data = json_decode(data)
    tmpSendMsgUtil = util.SendMsgUtil(request)
    res = home.save_gold(request, data)
    if res["res"] != True:
        tmpSendMsgUtil.update_res(res["res"])
    tmpSendMsgUtil.send(cmd)

def method_get_save_gold_info(request,data):
    '''查询我存钱的信息'''
    cmd = 'get_save_gold_info'
    data = json_decode(data)
    tmpSendMsgUtil = util.SendMsgUtil(request)
    tmpUser = user.UserManager.get_user_by_request(request)
    if not tmpUser:
        return
    tmpUid = tmpUser.getUID()
    roomer = user.UserManager.get_userinfo_record(tmpUid, "room_gold")
    if not roomer:
        return
    res = home.get_roomer_can_steal_gold(roomer.get('room_gold'),True)
    tmpSendMsgUtil.add_item("gold_info", res)   
    tmpSendMsgUtil.send(cmd)
    
    

#新建相册
def method_add_album(request, data): 
    cmd = 'add_album'
    data = json_decode(data)
    tmpSendMsgUtil = util.SendMsgUtil(request)
    res = home.add_album(request, data)
    if res["res"] != True:
        tmpSendMsgUtil.update_res(res["res"])
    tmpSendMsgUtil.send(cmd)
    

#删除相片、相册
def method_delete_album_photo(request, data): 
    cmd = 'delete_album_photo'
    data = json_decode(data)
    tmpSendMsgUtil = util.SendMsgUtil(request)
    res = home.del_album(request, data)
    if res["res"] != True:
        tmpSendMsgUtil.update_res(res["res"])
    else:
        user.UserManager.updateLogTotalPhotoDel() #----相片记录.....总数减一
    tmpSendMsgUtil.send(cmd)
    

#查询相册列表
def method_query_album_list(request, data): 
    cmd = 'query_album_list'
    data = json_decode(data)
    tmpSendMsgUtil = util.SendMsgUtil(request)  
    res = home.get_album(request, data, 'a')  
    if res["res"] != True:
        tmpSendMsgUtil.update_res(res["res"])
    else:        
        tmpSendMsgUtil.add_item("albums", res["a"]["list"])     
    tmpSendMsgUtil.send(cmd)

    
#查询相片列表
def method_query_photo_list(request, data): 
    cmd = 'query_photo_list'
    data = json_decode(data)
    tmpSendMsgUtil = util.SendMsgUtil(request)    
    res = home.get_album(request, data, 'p')  
    if res["res"] != True:
        tmpSendMsgUtil.update_res(res["res"])
    else:
        tmpSendMsgUtil.add_item("photos", res["p"]["list"])
    tmpSendMsgUtil.send(cmd)

    
#查询相片评论
def method_query_photo_words(request, data): 
    cmd = 'query_photo_words'
    data = json_decode(data)
    tmpSendMsgUtil = util.SendMsgUtil(request)
    res = home.get_album(request, data, 'c')  
    if res["res"] != True:
        tmpSendMsgUtil.update_res(res["res"])
    else:
        tmpSendMsgUtil.add_item("albums", res["c"]["list"])
    tmpSendMsgUtil.send(cmd)

    
#相片评论
def method_photo_leave_words(request, data): 
    cmd = 'photo_leave_words'
    data = json_decode(data)
    tmpSendMsgUtil = util.SendMsgUtil(request)
    res = home.add_photo_comment(request, data)
    if res["res"] != True:
        tmpSendMsgUtil.update_res(res["res"])  
    tmpSendMsgUtil.send(cmd)
 
    
#留言
def method_send_memo(request, data): 
    '''留言，私信'''
    cmd = 'send_memo'
    data = json_decode(data)
    tmpSendMsgUtil = util.SendMsgUtil(request)
    res = home.send_memo(request, data)
    if res["res"] != True:
        tmpSendMsgUtil.update_res(res["res"])
    else:
        u = user.UserManager.get_user_by_request(request)
        tmpUser = {}
        tmpUser["uid"] = u.getUID()
        tmpUser["nickname"] = u.getNickname()
        tmpSendMsgUtil.add_item("user", tmpUser)  #留言者者信息
        tmpSendMsgUtil.add_item("rec_id", res["last_rec_id"])
        right = data.get('right') 
        if right==0:
            user.UserManager.updateUserCount('count_leftmsg', 1, data.get('owner'))#增加统计数量
        if right==1:
            user.UserManager.updateUserCount('count_private_letter', 1, data.get('owner'))#增加统计数量
        tmpSendMsgUtil.add_item("right", right)  #留言或私信
    tmpSendMsgUtil.send(cmd)

    
#查看留言、来访记录
def method_query_house_history(request, data):
    cmd = 'query_house_history' 
    data = json_decode(data)
    tmpSendMsgUtil = util.SendMsgUtil(request)  
    res = home.get_msg(request, data)
    if res["res"] != True:
        tmpSendMsgUtil.update_res(res["res"])
    else:
        tmpSendMsgUtil.add_item("type", data["type"])
        tmpSendMsgUtil.add_item("list", res["list"])
        tmpSendMsgUtil.add_item("total", res["total"])
        tmpSendMsgUtil.add_item("act", data.get("act"))
    tmpSendMsgUtil.send(cmd)


#查看房主活跃记录
def method_query_house_owner_history(request,data):
    cmd = 'query_house_history'
    data = json_decode(data)
    tmpSendMsgUtil = util.SendMsgUtil(request)  
    res = home.get_act_msg(request, data)
    if res["res"] != True:
        tmpSendMsgUtil.update_res(res["res"])
    else:       
        tmpSendMsgUtil.add_item("user", res["user"])
    tmpSendMsgUtil.send(cmd)


#设置封面
def method_set_cover(request,data):
    cmd = 'set_cover'
    data = json_decode(data)
    tmpSendMsgUtil = util.SendMsgUtil(request)  
    res = home.set_cover(request, data)
    if res["res"] != True:
        tmpSendMsgUtil.update_res(res["res"])
    else:       
        tmpSendMsgUtil.add_item("photo_id", data["photo_id"])
    tmpSendMsgUtil.send(cmd)


#设置已读
def method_set_is_read(request,data):
    cmd = 'set_is_read'
    data = json_decode(data)
    tmpSendMsgUtil = util.SendMsgUtil(request)
    res = home.set_msg_is_got(request, data,'set')
    if res["res"] != True:
        tmpSendMsgUtil.update_res(res["res"])
    else:       
        tmpSendMsgUtil.add_item("rec_id", data["rec_id"])
    tmpSendMsgUtil.send(cmd)


#删除留言
def method_del_msg(request,data):
    cmd = 'del_msg'
    data = json_decode(data)
    tmpSendMsgUtil = util.SendMsgUtil(request)
    res = home.set_msg_is_got(request, data,'del')
    if res["res"] != True:
        tmpSendMsgUtil.update_res(res["res"])
    else:       
        tmpSendMsgUtil.add_item("rec_id", data["rec_id"])
    tmpSendMsgUtil.send(cmd)


#提取礼品
def method_get_present(request,data):
    cmd = 'get_present'
    data = json_decode(data)
    tmpSendMsgUtil = util.SendMsgUtil(request)
    res = home.get_present(request, data)
    if res["res"] != True:
        tmpSendMsgUtil.update_res(res["res"])
    else:       
        tmpSendMsgUtil.add_item("rec_id", data["rec_id"])
        tmpSendMsgUtil.add_item("id", data["id"])
    tmpSendMsgUtil.send(cmd)


#上传相片
def method_up_photo(request,data):
	cmd = 'up_photo'
	data = json_decode(data)
	tmpSendMsgUtil = util.SendMsgUtil(request)
    
	uid = data['uid']
	tmpType = data['type']   #1上传形象照片，2普通相片    
    
	to_user = user.UserManager.get_user_by_uid(uid)
	if not to_user:
		tmpSendMsgUtil.update_res("user_is_null")
	else: 
		to_request = to_user.m_request    
        
		if tmpType==1:
			util.CountUserUtil.judgeAndEditExt(cmd, to_request, uid, "up_head")
			user.UserManager.update_user(uid, {"is_upload_head":1})
		if tmpType==2:
			tmpCountUploadPhoto = 0
			if to_user.m_userinfo.get('count_upload_photo'):
				tmpCountUploadPhoto = to_user.m_userinfo.get('count_upload_photo')			
			if (tmpCountUploadPhoto+1)<=5:  #上传相片5张以上不加魅力
				util.CountUserUtil.judgeAndEditExt(cmd, to_request, uid, "up_photo")     
			user.UserManager.updateUserCount('count_upload_photo', 1, uid)#增加统计数量
            #----通知php, 写信息到用户被关注的人员的文本
			user.UserManager.sendLogFriendInfoUrl(uid, to_user.getNickname(), cmd)
        #----相片记录.....总数加一
        user.UserManager.updateLogTotalPhoto()
	tmpSendMsgUtil.send(cmd)


#好友印象
def method_send_impression(request,data):
    cmd = 'send_impression'
    data = json_decode(data)
    tmpSendMsgUtil = util.SendMsgUtil(request)
    res = home.send_impression(request, data)
    if res["res"] != True:
        tmpSendMsgUtil.update_res(res["res"])
    else:
        to_uid = data.get('uid')
        tmpSendMsgUtil.add_item('uid', data['uid'])  #留言者者信息
        tmpSendMsgUtil.add_item('rec_id', res["last_rec_id"])
        user.UserManager.updateUserCount('count_commented', 1, to_uid)#增加统计数量
        
        #被动者数值变化--[被评论多少次加魅力]----
        tmpTargetUser = user.UserManager.get_userinfo(to_uid, bGetUser=True);
        if tmpTargetUser:
            tmpLimit = const.Config_impressioned_get_charm_limit()
            if not tmpLimit:
                tmpLimit = 1
            tmpCount = tmpTargetUser.getUserInfoToInt("count_commented")
            if tmpCount > 0 and (tmpCount%tmpLimit) == 0:
            	tmpLogicMapObj = util.ConfigManager.getLogicInfo("default_logic") #获取默认配置项
            	util.ConfigManager.setLogicInfoVal_Charm(tmpLogicMapObj, 1)       #魅力增减
            	util.CountUserUtil.judgeAndEditExt(cmd, request, to_uid, tmpLogicMapObj, False)

				
    tmpSendMsgUtil.send(cmd)


#获取好友印象
def method_get_impression(request,data):
    cmd = 'get_impression'
    data = json_decode(data)
    tmpSendMsgUtil = util.SendMsgUtil(request)  
    res = home.get_impression(request, data)
    if res["res"] != True:
        tmpSendMsgUtil.update_res(res["res"])
    else:        
        tmpSendMsgUtil.add_item("list", res["list"])
    tmpSendMsgUtil.send(cmd)
    
def method_verify_user_photo(request,data):
    '''审核用户相片'''
    socket_id = request.socket_id   
    cmd = "verify_user_photo"
        
    tmpSendMsgUtil = util.SendMsgUtil(request)    #消息发送器
    
    data_dict = json_decode(data)	
    tmpReqAlbumID = data_dict.get('album_id')   #相册ID
    tmpReqPhotoID= data_dict.get('photo_id')    #相片id  
    tmpReqOwnerUID = data_dict.get('owner')        #用户ID 
    
    tmpReqType = data_dict.get('type')          #none: 默认不通过 
                                                #admit通过 (所有人能看见) 
                                                #warning 警告(不通过), 需通知用户, 并减少数值
                                                #delete 删除, 直接删除文件, 减少数值
                                                #advise 推荐头像 (加数值)
    if tmpReqType not in ['none', 'admit', 'warning', 'delete', 'advise']:
        tmpSendMsgUtil.update_res("bad_request")#参数错误
        tmpSendMsgUtil.send(cmd)
        return
    
    res = home.verify_user_photo(request, data_dict) #更新相片type
    if res["res"] != True:
        tmpSendMsgUtil.update_res(res["res"])
    else:
        #用户数值变化
        tmpCinfigName = "verify_user_photo_" % tmpReqType
        util.CountUserUtil.judgeAndEditExt(cmd, None, tmpReqOwnerUID, tmpCinfigName, False)

    tmpSendMsgUtil.send(cmd)

def method_clean_record(request,data):   
    '''清理记录'''
    socket_id = request.socket_id   
    cmd = "clean_record" 
    tmpSendMsgUtil = util.SendMsgUtil(request)    #消息发送器  
    tmpUser = user.UserManager.get_user_by_request(request)
   
    if not tmpUser:      
        tmpSendMsgUtil.update_res("user_is_null")#参数错误
        tmpSendMsgUtil.send(cmd)
        return
   
    tmpUid = tmpUser.getUID()
    data_dict = json_decode(data)
    toUid = data_dict.get('uid')
    tmpType = data_dict.get('type')
    if tmpType not in  ['guest_visit_rec','guest_clean_rec']:
        tmpSendMsgUtil.update_res("bad_request")#参数错误
        tmpSendMsgUtil.send(cmd)
        return
    tmpRecord = user.UserManager.get_userinfo_record(tmpUid, tmpType)
    
    if not tmpRecord:
        tmpSendMsgUtil.update_res("user_is_null")#用户不存在
        tmpSendMsgUtil.send(cmd)
        return
    tmpRecord = json_decode(tmpRecord.get(tmpType))    
    tmpLog = tmpRecord.get('log')
    if not tmpLog:
        tmpSendMsgUtil.update_res("user_is_null")#用户不存在
        tmpSendMsgUtil.send(cmd)
        return
    tmpSaveLog = []
    for v in tmpLog:
        if v.get('uid')!=toUid:
           tmpSaveLog.append(v)
    conn = mysql()
    tmpRecord['log']=tmpSaveLog    
    conn.upData('t_user_record', {tmpType:json_encode(tmpRecord)}, "WHERE uid=%d "%tmpUid,asyn=True)    
    tmpSendMsgUtil.send(cmd)

def method_get_house_info(request,data):
    '''获取房间信息，包括可读私信条数，脚印条数，可偷钱数'''
    socket_id = request.socket_id
    cmd = "get_house_info" 
    tmpSendMsgUtil = util.SendMsgUtil(request)    #消息发送器  
    tmpUser = user.UserManager.get_user_by_request(request)
   
    if not tmpUser:      
        tmpSendMsgUtil.update_res("user_is_null")#参数错误
        tmpSendMsgUtil.send(cmd)
        return
    print "@2@>tmpUser", tmpUser 
    data_dict = json_decode(data)
    print "@2@>data_dict", data_dict
    tmpUid = data_dict.get('uid')
    if not tmpUid:
        tmpUid = tmpUser.getUID()
    tmpRecord = user.UserManager.get_userinfo_record(tmpUid, " room_gold,guest_visit_rec,guest_leaveword ")
    if not tmpRecord:
        tmpSendMsgUtil.update_res("user_is_null")#参数错误
        tmpSendMsgUtil.send(cmd)
        return
    
    tmpCanStealGold = 0  #定义可以获得的金币数
    tmpCountVisitRec = 0 #定义来访次数
    tmpCountleaveMsg = 0 #定义留言条数
    tmpCountPrivateMsg = 0 #定义私信条数    (实际为发私信用户总数)
    tmpCountPrivateMsg_Nums = 0 #定义新私信总条数    ***wudi***
    tmpCountPresentMsg = 0 #定义礼品信息条数
    
    print "@2@>tmpRecord>", tmpRecord.keys()
    room_gold = tmpRecord.get('room_gold')
    guest_visit_rec = tmpRecord.get('guest_visit_rec')
    guest_leaveword = tmpRecord.get('guest_leaveword')    
    
    gold_info = home.get_roomer_can_steal_gold(room_gold, True)    
    tmpCanStealGold = gold_info.get('can_steal_gold')
    
    tmpVisitRec = []
    if guest_visit_rec:
        guest_visit_rec = json_decode(guest_visit_rec)
        if guest_visit_rec:
            tmpLog = guest_visit_rec.get('log')
            if tmpLog:
                for v in tmpLog:
                    if v['uid'] in tmpVisitRec:
                        continue
                    tmpVisitRec.append(v['uid'])
                
    tmpCountVisitRec = len(tmpVisitRec)
    
    tmpLeavewordRec = []
    tmpPrivateLeavewordRec = []
    tmpPresentLeavewordRec = []
    if guest_leaveword:
        guest_leaveword = json_decode(guest_leaveword)
        print "@2@>guest_leaveword>", type(guest_leaveword), guest_leaveword.keys(), guest_leaveword
        if guest_leaveword:
            tmpLog = guest_leaveword.get('log')
            if tmpLog:
                print "@2@>tmpLog>", type(tmpLog)
                for v in tmpLog:
                    print "@2@", v
                    if v.get('got')==0:
                        if v.get('right')==0:   #留言
                            if v['uid'] in tmpLeavewordRec:
                                continue
                            tmpLeavewordRec.append(v['uid'])
                        if v.get('right')==1:   #私信
                            tmpCountPrivateMsg_Nums += 1    #***wudi***
                            if v['uid'] in tmpPrivateLeavewordRec:
                                continue
                            tmpPrivateLeavewordRec.append(v['uid'])
                        if v.get('right')==2:   #礼物信息
                            if v['uid'] in tmpPresentLeavewordRec:
                                continue
                            tmpPresentLeavewordRec.append(v['uid'])
    
    tmpCountleaveMsg = len(tmpLeavewordRec)
    tmpCountPrivateMsg  = len(tmpPrivateLeavewordRec)
    print "@2@私信条数：", tmpCountPrivateMsg, tmpCountPrivateMsg_Nums
    tmpCountPresentMsg  = len(tmpPresentLeavewordRec)
    
    tmpSendMsgUtil.add_item("can_steal_gold", tmpCanStealGold)
    tmpSendMsgUtil.add_item("guest_visit_rec", tmpCountVisitRec)
    tmpSendMsgUtil.add_item("guest_leaveword", tmpCountleaveMsg)
    tmpSendMsgUtil.add_item("guest_private_leaveword", tmpCountPrivateMsg)
    tmpSendMsgUtil.add_item("guest_present_leaveword", tmpCountPresentMsg)
    
    guest_private_leaveword_newmsg= '<font color="#FFFF00">欢迎来到恋爱之城，您收到了 %d 封私信。</font>'%(tmpCountPrivateMsg_Nums)  #***wudi***
    print "@2@>", guest_private_leaveword_newmsg
    tmpSendMsgUtil.add_item("guest_private_leaveword_newmsg", guest_private_leaveword_newmsg)   #***wudi***
    
    tmpSendMsgUtil.send(cmd)

def _get_neighbor_info(tmpUser):
    '''获取某人里的邻居信息'''
    tmpResList = []
    if not tmpUser:
        return tmpResList
    
    #--获取UID列表
    tmpList = tmpUser.getMyNeighbor() #[uid, uid]
    if len(tmpList) == 0:
        tmpList = HallOfFameManager.instance().getUIDListExt(parmsSex=tmpUser.getDiffentSex(), tmpCount=4)  #从名人堂排序队列获取uid列表
        tmpUser.setMyNeighbor(tmpList)                      #保存到缓存
        user.UserManager.updateDBUserMyNeighbor(tmpUser)    #保存用户的邻居到DB
        
    for tmpNeighborUID in tmpList:
        bTargetUserOnline, tmpNeighborUser = user.UserManager.getUserObjByUID(tmpNeighborUID)
        if tmpNeighborUser:
             tmpClientDict = BarOrderManager.instance().getUserInfoToClient(tmpNeighborUser)
             tmpClientDict["friend_type"]= tmpUser.getFriendType(tmpNeighborUID)  #好友类型, “default”:陌生人  “my_attt” 我关注的,   “my_hidden_love”: 我暗恋的,
             tmpResList.append(tmpClientDict)  
    return tmpResList


def method_get_neighbor(request,data): 
    '''获取某人的邻居信息'''
    socket_id = request.socket_id
    log.print_debug(logger, "method_get_neighbor exec, socket_id:[%s], data:%s" % (socket_id, data)) 
    cmd = "get_neighbor"
        
    tmpSendMsgUtil = util.SendMsgUtil(request)    #消息发送器    
    tmpOwnerUser = user.UserManager.getUserExt(cmd, tmpSendMsgUtil, socket_id);     
    if tmpOwnerUser is None: #当前用户对象不存在， 则发错误消息
        return
    
    data_dict = json_decode(data) 
    tmpReqUID = data_dict.get('uid', tmpOwnerUser.getUID())     #被请求者UID

    bTargetUserOnline, tmpTargetUser = user.UserManager.getUserObjByUID(tmpReqUID) #用户对象  
    if tmpTargetUser is None:
        log.print_warning(logger, "method_get_neighbor exec, tmpReqUID:[%s] is null" % tmpReqUID) 
        tmpSendMsgUtil.update_res("user_is_null")     
        tmpSendMsgUtil.send(cmd) 
        return
     
    tmpNeighborInfo = _get_neighbor_info(tmpTargetUser)  #获取邻居信息
    tmpSendMsgUtil.add_item("neighbor", tmpNeighborInfo)
    tmpSendMsgUtil.send(cmd) 

def method_change_neighbor(request,data): 
    '''更换邻居信息'''
    socket_id = request.socket_id
    log.print_debug(logger, "method_change_neighbor exec, socket_id:[%s], data:%s" % (socket_id, data)) 
    cmd = "change_neighbor"
        
    tmpSendMsgUtil = util.SendMsgUtil(request)    #消息发送器    
    tmpOwnerUser = user.UserManager.getUserExt(cmd, tmpSendMsgUtil, socket_id);     
    if tmpOwnerUser is None: #当前用户对象不存在， 则发错误消息
        return

    data_dict = json_decode(data) 
    tmpReqUID = data_dict.get('uid', tmpOwnerUser.getUID())     #被请求者UID

    bTargetUserOnline, tmpTargetUser = user.UserManager.getUserObjByUID(tmpReqUID) #用户对象  
    if tmpTargetUser is None:
        log.print_warning(logger, "method_change_neighbor exec, tmpReqUID:[%s] is null" % tmpReqUID) 
        tmpSendMsgUtil.update_res("user_is_null")     
        tmpSendMsgUtil.send(cmd) 
        return
    
    if not util.CountUserUtil.judgeAndEditExt(cmd, request, tmpOwnerUser.getUID(), "Config_change_neighbor"):
        return  #数值扣除不成功, 则返回
     
    tmpTargetUser.setMyNeighbor([])  #清空邻居信息
    tmpNeighborInfo = _get_neighbor_info(tmpTargetUser)  #获取邻居信息
    tmpSendMsgUtil.add_item("neighbor", tmpNeighborInfo)
    tmpSendMsgUtil.send(cmd) 

        
util.registMethod("enter_house", method_enter_house)                               #进入房间
util.registMethod("enter_room", method_enter_room)                                 #进入公寓
util.registMethod("set_clothing", method_set_clothing)                             #衣服穿戴
util.registMethod("set_furniture", method_set_furniture)                           #家具摆放
util.registMethod("clean_house", method_clean_house)                               #打扫房间
util.registMethod("steal_gold", method_steal_gold)                                 #偷钱
util.registMethod("save_gold", method_save_gold)                                   #存钱
util.registMethod("get_save_gold_info", method_get_save_gold_info)                 #存钱
util.registMethod("add_album", method_add_album)                                   #新建相册
util.registMethod("delete_album_photo", method_delete_album_photo)                 #删除相片、相册
util.registMethod("query_album_list", method_query_album_list)                     #查询相册列表
util.registMethod("query_photo_list", method_query_photo_list)                     #查询相片列表
util.registMethod("query_photo_words", method_query_photo_words)                   #查询相片评论
util.registMethod("photo_leave_words", method_photo_leave_words)                   #相片留言
util.registMethod("send_memo", method_send_memo)                                   #留言
util.registMethod("query_house_history", method_query_house_history)               #查看留言、来访记录
util.registMethod("query_house_owner_history", method_query_house_owner_history)   #查看房主活跃记录
util.registMethod("set_cover", method_set_cover)                                   #设置封面
util.registMethod("set_is_read", method_set_is_read)                               #私信设置已读
util.registMethod("del_msg", method_del_msg)                                       #删除留言
util.registMethod("get_present", method_get_present)                               #提取礼品
util.registMethod("up_photo", method_up_photo)                                     #上传相片
util.registMethod("send_impression", method_send_impression)                       #评论好友印象
util.registMethod("get_impression", method_get_impression)                         #获取好友印象
util.registMethod("verify_user_photo", method_verify_user_photo)                   #审核用户相片
util.registMethod("clean_record", method_clean_record)                             #清理记录

util.registMethod("get_house_info", method_get_house_info)                         #获取房间信息

util.registMethod("get_neighbor", method_get_neighbor)                              #获取邻居信息
util.registMethod("change_neighbor", method_change_neighbor)                        #更换邻居信息
